import config from "./config";

export default (url, data = {}, method = 'GET') => {
    return new Promise((resolve, reject) => {
        wx.request({
          url: config.host + url, //仅为示例，并非真实的接口地址
            data,
            method,
            header: {
                cookie: wx.getStorageSync('cookies') ? wx.getStorageSync('cookies').find(item => {
                    return item.indexOf('MUSIC_U') !== -1
                }) : ''
            },
            success(res) {
                if (data.isLogin) {
                    wx.setStorage({
                        key: 'cookies',
                        data: res.cookies
                    })
                }
                resolve(res.data)
            },
            fail(err) {
                reject(err)
            }
        })
    })
}
